<?php

/**
 * 
 *
 * @version 1.107
 * @package entity
 */
class ClUsuarioModel extends Db2PhpEntityBase implements Db2PhpEntityModificationTracking {
	private static $CLASS_NAME='ClUsuarioModel';
	const SQL_IDENTIFIER_QUOTE='';
	const SQL_TABLE_NAME='cl_usuario';
	const SQL_INSERT='INSERT INTO cl_usuario (id_usuario,identificacion,tipo_identificacion,apellido,nombre,direccion,telefono,celular,mail,fecha_nacimiento,estudiante_uniatlantico,fecha_registro,activo,antiguo) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
	const SQL_INSERT_AUTOINCREMENT='INSERT INTO cl_usuario (identificacion,tipo_identificacion,apellido,nombre,direccion,telefono,celular,mail,fecha_nacimiento,estudiante_uniatlantico,fecha_registro,activo,antiguo) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)';
	const SQL_UPDATE='UPDATE cl_usuario SET id_usuario=?,identificacion=?,tipo_identificacion=?,apellido=?,nombre=?,direccion=?,telefono=?,celular=?,mail=?,fecha_nacimiento=?,estudiante_uniatlantico=?,fecha_registro=?,activo=?,antiguo=? WHERE id_usuario=?';
	const SQL_SELECT_PK='SELECT * FROM cl_usuario WHERE id_usuario=?';
	const SQL_DELETE_PK='DELETE FROM cl_usuario WHERE id_usuario=?';
	const FIELD_ID_USUARIO=1099957856;
	const FIELD_IDENTIFICACION=-1864558731;
	const FIELD_TIPO_IDENTIFICACION=-1573459212;
	const FIELD_APELLIDO=-1219672908;
	const FIELD_NOMBRE=-394029793;
	const FIELD_DIRECCION=-1153564646;
	const FIELD_TELEFONO=850113226;
	const FIELD_CELULAR=-789282372;
	const FIELD_MAIL=2068818061;
	const FIELD_FECHA_NACIMIENTO=2106902257;
	const FIELD_ESTUDIANTE_UNIATLANTICO=531693294;
	const FIELD_FECHA_REGISTRO=1932019211;
	const FIELD_ACTIVO=-777075610;
	const FIELD_ANTIGUO=1995366409;
	private static $PRIMARY_KEYS=array(self::FIELD_ID_USUARIO);
	private static $AUTOINCREMENT_FIELDS=array(self::FIELD_ID_USUARIO);
	private static $FIELD_NAMES=array(
		self::FIELD_ID_USUARIO=>'id_usuario',
		self::FIELD_IDENTIFICACION=>'identificacion',
		self::FIELD_TIPO_IDENTIFICACION=>'tipo_identificacion',
		self::FIELD_APELLIDO=>'apellido',
		self::FIELD_NOMBRE=>'nombre',
		self::FIELD_DIRECCION=>'direccion',
		self::FIELD_TELEFONO=>'telefono',
		self::FIELD_CELULAR=>'celular',
		self::FIELD_MAIL=>'mail',
		self::FIELD_FECHA_NACIMIENTO=>'fecha_nacimiento',
		self::FIELD_ESTUDIANTE_UNIATLANTICO=>'estudiante_uniatlantico',
		self::FIELD_FECHA_REGISTRO=>'fecha_registro',
		self::FIELD_ACTIVO=>'activo',
		self::FIELD_ANTIGUO=>'antiguo');
	private static $PROPERTY_NAMES=array(
		self::FIELD_ID_USUARIO=>'idUsuario',
		self::FIELD_IDENTIFICACION=>'identificacion',
		self::FIELD_TIPO_IDENTIFICACION=>'tipoIdentificacion',
		self::FIELD_APELLIDO=>'apellido',
		self::FIELD_NOMBRE=>'nombre',
		self::FIELD_DIRECCION=>'direccion',
		self::FIELD_TELEFONO=>'telefono',
		self::FIELD_CELULAR=>'celular',
		self::FIELD_MAIL=>'mail',
		self::FIELD_FECHA_NACIMIENTO=>'fechaNacimiento',
		self::FIELD_ESTUDIANTE_UNIATLANTICO=>'estudianteUniatlantico',
		self::FIELD_FECHA_REGISTRO=>'fechaRegistro',
		self::FIELD_ACTIVO=>'activo',
		self::FIELD_ANTIGUO=>'antiguo');
	private static $PROPERTY_TYPES=array(
		self::FIELD_ID_USUARIO=>Db2PhpEntity::PHP_TYPE_FLOAT,
		self::FIELD_IDENTIFICACION=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_TIPO_IDENTIFICACION=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_APELLIDO=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_NOMBRE=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_DIRECCION=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_TELEFONO=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_CELULAR=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_MAIL=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_FECHA_NACIMIENTO=>Db2PhpEntity::PHP_TYPE_STRING,
		self::FIELD_ESTUDIANTE_UNIATLANTICO=>Db2PhpEntity::PHP_TYPE_BOOL,
		self::FIELD_FECHA_REGISTRO=>Db2PhpEntity::PHP_TYPE_FLOAT,
		self::FIELD_ACTIVO=>Db2PhpEntity::PHP_TYPE_BOOL,
		self::FIELD_ANTIGUO=>Db2PhpEntity::PHP_TYPE_BOOL);
	private static $FIELD_TYPES=array(
		self::FIELD_ID_USUARIO=>array(Db2PhpEntity::JDBC_TYPE_BIGINT,20,0,false),
		self::FIELD_IDENTIFICACION=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,20,0,false),
		self::FIELD_TIPO_IDENTIFICACION=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,2,0,false),
		self::FIELD_APELLIDO=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,30,0,false),
		self::FIELD_NOMBRE=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,30,0,false),
		self::FIELD_DIRECCION=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,60,0,true),
		self::FIELD_TELEFONO=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,16,0,true),
		self::FIELD_CELULAR=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,16,0,true),
		self::FIELD_MAIL=>array(Db2PhpEntity::JDBC_TYPE_VARCHAR,60,0,true),
		self::FIELD_FECHA_NACIMIENTO=>array(Db2PhpEntity::JDBC_TYPE_DATE,10,0,true),
		self::FIELD_ESTUDIANTE_UNIATLANTICO=>array(Db2PhpEntity::JDBC_TYPE_BIT,0,0,false),
		self::FIELD_FECHA_REGISTRO=>array(Db2PhpEntity::JDBC_TYPE_BIGINT,19,0,false),
		self::FIELD_ACTIVO=>array(Db2PhpEntity::JDBC_TYPE_BIT,0,0,false),
		self::FIELD_ANTIGUO=>array(Db2PhpEntity::JDBC_TYPE_BIT,0,0,false));
	private static $DEFAULT_VALUES=array(
		self::FIELD_ID_USUARIO=>null,
		self::FIELD_IDENTIFICACION=>'',
		self::FIELD_TIPO_IDENTIFICACION=>'',
		self::FIELD_APELLIDO=>'',
		self::FIELD_NOMBRE=>'',
		self::FIELD_DIRECCION=>null,
		self::FIELD_TELEFONO=>null,
		self::FIELD_CELULAR=>null,
		self::FIELD_MAIL=>null,
		self::FIELD_FECHA_NACIMIENTO=>null,
		self::FIELD_ESTUDIANTE_UNIATLANTICO=>'0',
		self::FIELD_FECHA_REGISTRO=>0,
		self::FIELD_ACTIVO=>'1',
		self::FIELD_ANTIGUO=>'0');
	private $idUsuario;
	private $identificacion;
	private $tipoIdentificacion;
	private $apellido;
	private $nombre;
	private $direccion;
	private $telefono;
	private $celular;
	private $mail;
	private $fechaNacimiento;
	private $estudianteUniatlantico;
	private $fechaRegistro;
	private $activo;
	private $antiguo;

	/**
	 * set value for id_usuario 
	 *
	 * type:BIGINT UNSIGNED,size:20,default:null,primary,unique,autoincrement
	 *
	 * @param mixed $idUsuario
	 * @return ClUsuarioModel
	 */
	public function &setIdUsuario($idUsuario) {
		$this->notifyChanged(self::FIELD_ID_USUARIO,$this->idUsuario,$idUsuario);
		$this->idUsuario=$idUsuario;
		return $this;
	}

	/**
	 * get value for id_usuario 
	 *
	 * type:BIGINT UNSIGNED,size:20,default:null,primary,unique,autoincrement
	 *
	 * @return mixed
	 */
	public function getIdUsuario() {
		return $this->idUsuario;
	}

	/**
	 * set value for identificacion 
	 *
	 * type:VARCHAR,size:20,default:null
	 *
	 * @param mixed $identificacion
	 * @return ClUsuarioModel
	 */
	public function &setIdentificacion($identificacion) {
		$this->notifyChanged(self::FIELD_IDENTIFICACION,$this->identificacion,$identificacion);
		$this->identificacion=$identificacion;
		return $this;
	}

	/**
	 * get value for identificacion 
	 *
	 * type:VARCHAR,size:20,default:null
	 *
	 * @return mixed
	 */
	public function getIdentificacion() {
		return $this->identificacion;
	}

	/**
	 * set value for tipo_identificacion 
	 *
	 * type:VARCHAR,size:2,default:null
	 *
	 * @param mixed $tipoIdentificacion
	 * @return ClUsuarioModel
	 */
	public function &setTipoIdentificacion($tipoIdentificacion) {
		$this->notifyChanged(self::FIELD_TIPO_IDENTIFICACION,$this->tipoIdentificacion,$tipoIdentificacion);
		$this->tipoIdentificacion=$tipoIdentificacion;
		return $this;
	}

	/**
	 * get value for tipo_identificacion 
	 *
	 * type:VARCHAR,size:2,default:null
	 *
	 * @return mixed
	 */
	public function getTipoIdentificacion() {
		return $this->tipoIdentificacion;
	}

	/**
	 * set value for apellido 
	 *
	 * type:VARCHAR,size:30,default:null
	 *
	 * @param mixed $apellido
	 * @return ClUsuarioModel
	 */
	public function &setApellido($apellido) {
		$this->notifyChanged(self::FIELD_APELLIDO,$this->apellido,$apellido);
		$this->apellido=$apellido;
		return $this;
	}

	/**
	 * get value for apellido 
	 *
	 * type:VARCHAR,size:30,default:null
	 *
	 * @return mixed
	 */
	public function getApellido() {
		return $this->apellido;
	}

	/**
	 * set value for nombre 
	 *
	 * type:VARCHAR,size:30,default:null
	 *
	 * @param mixed $nombre
	 * @return ClUsuarioModel
	 */
	public function &setNombre($nombre) {
		$this->notifyChanged(self::FIELD_NOMBRE,$this->nombre,$nombre);
		$this->nombre=$nombre;
		return $this;
	}

	/**
	 * get value for nombre 
	 *
	 * type:VARCHAR,size:30,default:null
	 *
	 * @return mixed
	 */
	public function getNombre() {
		return $this->nombre;
	}

	/**
	 * set value for direccion 
	 *
	 * type:VARCHAR,size:60,default:null,nullable
	 *
	 * @param mixed $direccion
	 * @return ClUsuarioModel
	 */
	public function &setDireccion($direccion) {
		$this->notifyChanged(self::FIELD_DIRECCION,$this->direccion,$direccion);
		$this->direccion=$direccion;
		return $this;
	}

	/**
	 * get value for direccion 
	 *
	 * type:VARCHAR,size:60,default:null,nullable
	 *
	 * @return mixed
	 */
	public function getDireccion() {
		return $this->direccion;
	}

	/**
	 * set value for telefono 
	 *
	 * type:VARCHAR,size:16,default:null,nullable
	 *
	 * @param mixed $telefono
	 * @return ClUsuarioModel
	 */
	public function &setTelefono($telefono) {
		$this->notifyChanged(self::FIELD_TELEFONO,$this->telefono,$telefono);
		$this->telefono=$telefono;
		return $this;
	}

	/**
	 * get value for telefono 
	 *
	 * type:VARCHAR,size:16,default:null,nullable
	 *
	 * @return mixed
	 */
	public function getTelefono() {
		return $this->telefono;
	}

	/**
	 * set value for celular 
	 *
	 * type:VARCHAR,size:16,default:null,nullable
	 *
	 * @param mixed $celular
	 * @return ClUsuarioModel
	 */
	public function &setCelular($celular) {
		$this->notifyChanged(self::FIELD_CELULAR,$this->celular,$celular);
		$this->celular=$celular;
		return $this;
	}

	/**
	 * get value for celular 
	 *
	 * type:VARCHAR,size:16,default:null,nullable
	 *
	 * @return mixed
	 */
	public function getCelular() {
		return $this->celular;
	}

	/**
	 * set value for mail 
	 *
	 * type:VARCHAR,size:60,default:null,nullable
	 *
	 * @param mixed $mail
	 * @return ClUsuarioModel
	 */
	public function &setMail($mail) {
		$this->notifyChanged(self::FIELD_MAIL,$this->mail,$mail);
		$this->mail=$mail;
		return $this;
	}

	/**
	 * get value for mail 
	 *
	 * type:VARCHAR,size:60,default:null,nullable
	 *
	 * @return mixed
	 */
	public function getMail() {
		return $this->mail;
	}

	/**
	 * set value for fecha_nacimiento 
	 *
	 * type:DATE,size:10,default:null,nullable
	 *
	 * @param mixed $fechaNacimiento
	 * @return ClUsuarioModel
	 */
	public function &setFechaNacimiento($fechaNacimiento) {
		$this->notifyChanged(self::FIELD_FECHA_NACIMIENTO,$this->fechaNacimiento,$fechaNacimiento);
		$this->fechaNacimiento=$fechaNacimiento;
		return $this;
	}

	/**
	 * get value for fecha_nacimiento 
	 *
	 * type:DATE,size:10,default:null,nullable
	 *
	 * @return mixed
	 */
	public function getFechaNacimiento() {
		return $this->fechaNacimiento;
	}

	/**
	 * set value for estudiante_uniatlantico 
	 *
	 * type:BIT,size:0,default:0
	 *
	 * @param mixed $estudianteUniatlantico
	 * @return ClUsuarioModel
	 */
	public function &setEstudianteUniatlantico($estudianteUniatlantico) {
		$this->notifyChanged(self::FIELD_ESTUDIANTE_UNIATLANTICO,$this->estudianteUniatlantico,$estudianteUniatlantico);
		$this->estudianteUniatlantico=$estudianteUniatlantico;
		return $this;
	}

	/**
	 * get value for estudiante_uniatlantico 
	 *
	 * type:BIT,size:0,default:0
	 *
	 * @return mixed
	 */
	public function getEstudianteUniatlantico() {
		return $this->estudianteUniatlantico;
	}

	/**
	 * set value for fecha_registro 
	 *
	 * type:BIGINT,size:19,default:null
	 *
	 * @param mixed $fechaRegistro
	 * @return ClUsuarioModel
	 */
	public function &setFechaRegistro($fechaRegistro) {
		$this->notifyChanged(self::FIELD_FECHA_REGISTRO,$this->fechaRegistro,$fechaRegistro);
		$this->fechaRegistro=$fechaRegistro;
		return $this;
	}

	/**
	 * get value for fecha_registro 
	 *
	 * type:BIGINT,size:19,default:null
	 *
	 * @return mixed
	 */
	public function getFechaRegistro() {
		return $this->fechaRegistro;
	}

	/**
	 * set value for activo 
	 *
	 * type:BIT,size:0,default:1
	 *
	 * @param mixed $activo
	 * @return ClUsuarioModel
	 */
	public function &setActivo($activo) {
		$this->notifyChanged(self::FIELD_ACTIVO,$this->activo,$activo);
		$this->activo=$activo;
		return $this;
	}

	/**
	 * get value for activo 
	 *
	 * type:BIT,size:0,default:1
	 *
	 * @return mixed
	 */
	public function getActivo() {
		return $this->activo;
	}

	/**
	 * set value for antiguo 
	 *
	 * type:BIT,size:0,default:0
	 *
	 * @param mixed $antiguo
	 * @return ClUsuarioModel
	 */
	public function &setAntiguo($antiguo) {
		$this->notifyChanged(self::FIELD_ANTIGUO,$this->antiguo,$antiguo);
		$this->antiguo=$antiguo;
		return $this;
	}

	/**
	 * get value for antiguo 
	 *
	 * type:BIT,size:0,default:0
	 *
	 * @return mixed
	 */
	public function getAntiguo() {
		return $this->antiguo;
	}

	/**
	 * Get table name
	 *
	 * @return string
	 */
	public static function getTableName() {
		return self::SQL_TABLE_NAME;
	}

	/**
	 * Get array with field id as index and field name as value
	 *
	 * @return array
	 */
	public static function getFieldNames() {
		return self::$FIELD_NAMES;
	}

	/**
	 * Get array with field id as index and property name as value
	 *
	 * @return array
	 */
	public static function getPropertyNames() {
		return self::$PROPERTY_NAMES;
	}

	/**
	 * get the field name for the passed field id.
	 *
	 * @param int $fieldId
	 * @param bool $fullyQualifiedName true if field name should be qualified by table name
	 * @return string field name for the passed field id, null if the field doesn't exist
	 */
	public static function getFieldNameByFieldId($fieldId, $fullyQualifiedName=true) {
		if (!array_key_exists($fieldId, self::$FIELD_NAMES)) {
			return null;
		}
		$fieldName=self::SQL_IDENTIFIER_QUOTE . self::$FIELD_NAMES[$fieldId] . self::SQL_IDENTIFIER_QUOTE;
		if ($fullyQualifiedName) {
			return self::SQL_IDENTIFIER_QUOTE . self::SQL_TABLE_NAME . self::SQL_IDENTIFIER_QUOTE . '.' . $fieldName;
		}
		return $fieldName;
	}

	/**
	 * Get array with field ids of identifiers
	 *
	 * @return array
	 */
	public static function getIdentifierFields() {
		return self::$PRIMARY_KEYS;
	}

	/**
	 * Get array with field ids of autoincrement fields
	 *
	 * @return array
	 */
	public static function getAutoincrementFields() {
		return self::$AUTOINCREMENT_FIELDS;
	}

	/**
	 * Get array with field id as index and property type as value
	 *
	 * @return array
	 */
	public static function getPropertyTypes() {
		return self::$PROPERTY_TYPES;
	}

	/**
	 * Get array with field id as index and field type as value
	 *
	 * @return array
	 */
	public static function getFieldTypes() {
		return self::$FIELD_TYPES;
	}

	/**
	 * Assign default values according to table
	 * 
	 */
	public function assignDefaultValues() {
		$this->assignByArray(self::$DEFAULT_VALUES);
	}


	/**
	 * return hash with the field name as index and the field value as value.
	 *
	 * @return array
	 */
	public function toHash() {
		$array=$this->toArray();
		$hash=array();
		foreach ($array as $fieldId=>$value) {
			$hash[self::$FIELD_NAMES[$fieldId]]=$value;
		}
		return $hash;
	}

	/**
	 * return array with the field id as index and the field value as value.
	 *
	 * @return array
	 */
	public function toArray() {
		return array(
			self::FIELD_ID_USUARIO=>$this->getIdUsuario(),
			self::FIELD_IDENTIFICACION=>$this->getIdentificacion(),
			self::FIELD_TIPO_IDENTIFICACION=>$this->getTipoIdentificacion(),
			self::FIELD_APELLIDO=>$this->getApellido(),
			self::FIELD_NOMBRE=>$this->getNombre(),
			self::FIELD_DIRECCION=>$this->getDireccion(),
			self::FIELD_TELEFONO=>$this->getTelefono(),
			self::FIELD_CELULAR=>$this->getCelular(),
			self::FIELD_MAIL=>$this->getMail(),
			self::FIELD_FECHA_NACIMIENTO=>$this->getFechaNacimiento(),
			self::FIELD_ESTUDIANTE_UNIATLANTICO=>$this->getEstudianteUniatlantico(),
			self::FIELD_FECHA_REGISTRO=>$this->getFechaRegistro(),
			self::FIELD_ACTIVO=>$this->getActivo(),
			self::FIELD_ANTIGUO=>$this->getAntiguo());
	}


	/**
	 * return array with the field id as index and the field value as value for the identifier fields.
	 *
	 * @return array
	 */
	public function getPrimaryKeyValues() {
		return array(
			self::FIELD_ID_USUARIO=>$this->getIdUsuario());
	}

	/**
	 * cached statements
	 *
	 * @var array<string,array<string,PDOStatement>>
	 */
	private static $stmts=array();
	private static $cacheStatements=true;
	
	/**
	 * prepare passed string as statement or return cached if enabled and available
	 *
	 * @param PDO $db
	 * @param string $statement
	 * @return PDOStatement
	 */
	protected static function prepareStatement(PDO $db, $statement) {
		if(self::isCacheStatements()) {
			if (in_array($statement, array(self::SQL_INSERT, self::SQL_INSERT_AUTOINCREMENT, self::SQL_UPDATE, self::SQL_SELECT_PK, self::SQL_DELETE_PK))) {
				$dbInstanceId=spl_object_hash($db);
				if (empty(self::$stmts[$statement][$dbInstanceId])) {
					self::$stmts[$statement][$dbInstanceId]=$db->prepare($statement);
				}
				return self::$stmts[$statement][$dbInstanceId];
			}
		}
		return $db->prepare($statement);
	}

	/**
	 * Enable statement cache
	 *
	 * @param bool $cache
	 */
	public static function setCacheStatements($cache) {
		self::$cacheStatements=true==$cache;
	}

	/**
	 * Check if statement cache is enabled
	 *
	 * @return bool
	 */
	public static function isCacheStatements() {
		return self::$cacheStatements;
	}
	
	/**
	 * check if this instance exists in the database
	 *
	 * @param PDO $db
	 * @return bool
	 */
	public function existsInDatabase(PDO $db) {
		$filter=array();
		foreach ($this->getPrimaryKeyValues() as $fieldId=>$value) {
			$filter[]=new DFC($fieldId, $value, DFC::EXACT_NULLSAFE);
		}
		return 0!=count(self::findByFilter($db, $filter, true));
	}
	
	/**
	 * Update to database if exists, otherwise insert
	 *
	 * @param PDO $db
	 * @return mixed
	 */
	public function updateInsertToDatabase(PDO $db) {
		if ($this->existsInDatabase($db)) {
			return $this->updateToDatabase($db);
		} else {
			return $this->insertIntoDatabase($db);
		}
	}

	/**
	 * Query by Example.
	 *
	 * Match by attributes of passed example instance and return matched rows as an array of ClUsuarioModel instances
	 *
	 * @param PDO $db a PDO Database instance
	 * @param ClUsuarioModel $example an example instance defining the conditions. All non-null properties will be considered a constraint, null values will be ignored.
	 * @param boolean $and true if conditions should be and'ed, false if they should be or'ed
	 * @param array $sort array of DSC instances
	 * @return ClUsuarioModel[]
	 */
	public static function findByExample(PDO $db,ClUsuarioModel $example, $and=true, $sort=null) {
		$exampleValues=$example->toArray();
		$filter=array();
		foreach ($exampleValues as $fieldId=>$value) {
			if (null!==$value) {
				$filter[$fieldId]=$value;
			}
		}
		return self::findByFilter($db, $filter, $and, $sort);
	}

	/**
	 * Query by filter.
	 *
	 * The filter can be either an hash with the field id as index and the value as filter value,
	 * or a array of DFC instances.
	 *
	 * Will return matched rows as an array of ClUsuarioModel instances.
	 *
	 * @param PDO $db a PDO Database instance
	 * @param array $filter array of DFC instances defining the conditions
	 * @param boolean $and true if conditions should be and'ed, false if they should be or'ed
	 * @param array $sort array of DSC instances
	 * @return ClUsuarioModel[]
	 */
	public static function findByFilter(PDO $db, $filter, $and=true, $sort=null) {
		if (!($filter instanceof DFCInterface)) {
			$filter=new DFCAggregate($filter, $and);
		}
		$sql='SELECT * FROM cl_usuario'
		. self::buildSqlWhere($filter, $and, false, true)
		. self::buildSqlOrderBy($sort);

		$stmt=self::prepareStatement($db, $sql);
		self::bindValuesForFilter($stmt, $filter);
		return self::fromStatement($stmt);
	}

	/**
	 * Will execute the passed statement and return the result as an array of ClUsuarioModel instances
	 *
	 * @param PDOStatement $stmt
	 * @return ClUsuarioModel[]
	 */
	public static function fromStatement(PDOStatement $stmt) {
		$affected=$stmt->execute();
		if (false===$affected) {
			$stmt->closeCursor();
			throw new Exception($stmt->errorCode() . ':' . var_export($stmt->errorInfo(), true), 0);
		}
		return self::fromExecutedStatement($stmt);
	}

	/**
	 * returns the result as an array of ClUsuarioModel instances without executing the passed statement
	 *
	 * @param PDOStatement $stmt
	 * @return ClUsuarioModel[]
	 */
	public static function fromExecutedStatement(PDOStatement $stmt) {
		$resultInstances=array();
		while($result=$stmt->fetch(PDO::FETCH_ASSOC)) {
			$o=new ClUsuarioModel();
			$o->assignByHash($result);
			$o->notifyPristine();
			$resultInstances[]=$o;
		}
		$stmt->closeCursor();
		return $resultInstances;
	}

	/**
	 * Get sql WHERE part from filter.
	 *
	 * @param array $filter
	 * @param bool $and
	 * @param bool $fullyQualifiedNames true if field names should be qualified by table name
	 * @param bool $prependWhere true if WHERE should be prepended to conditions
	 * @return string
	 */
	public static function buildSqlWhere($filter, $and, $fullyQualifiedNames=true, $prependWhere=false) {
		if (!($filter instanceof DFCInterface)) {
			$filter=new DFCAggregate($filter, $and);
		}
		return $filter->buildSqlWhere(new self::$CLASS_NAME, $fullyQualifiedNames, $prependWhere);
	}

	/**
	 * get sql ORDER BY part from DSCs
	 *
	 * @param array $sort array of DSC instances
	 * @return string
	 */
	protected static function buildSqlOrderBy($sort) {
		return DSC::buildSqlOrderBy(new self::$CLASS_NAME, $sort);
	}

	/**
	 * bind values from filter to statement
	 *
	 * @param PDOStatement $stmt
	 * @param DFCInterface $filter
	 */
	public static function bindValuesForFilter(PDOStatement &$stmt, DFCInterface $filter) {
		$filter->bindValuesForFilter(new self::$CLASS_NAME, $stmt);
	}

	/**
	 * Execute select query and return matched rows as an array of ClUsuarioModel instances.
	 *
	 * The query should of course be on the table for this entity class and return all fields.
	 *
	 * @param PDO $db a PDO Database instance
	 * @param string $sql
	 * @return ClUsuarioModel[]
	 */
	public static function findBySql(PDO $db, $sql) {
		$stmt=$db->query($sql);
		return self::fromExecutedStatement($stmt);
	}

	/**
	 * Delete rows matching the filter
	 *
	 * The filter can be either an hash with the field id as index and the value as filter value,
	 * or a array of DFC instances.
	 *
	 * @param PDO $db
	 * @param array $filter
	 * @param bool $and
	 * @return mixed
	 */
	public static function deleteByFilter(PDO $db, $filter, $and=true) {
		if (!($filter instanceof DFCInterface)) {
			$filter=new DFCAggregate($filter, $and);
		}
		if (0==count($filter)) {
			throw new InvalidArgumentException('refusing to delete without filter'); // just comment out this line if you are brave
		}
		$sql='DELETE FROM cl_usuario'
		. self::buildSqlWhere($filter, $and, false, true);
		$stmt=self::prepareStatement($db, $sql);
		self::bindValuesForFilter($stmt, $filter);
		$affected=$stmt->execute();
		if (false===$affected) {
			$stmt->closeCursor();
			throw new Exception($stmt->errorCode() . ':' . var_export($stmt->errorInfo(), true), 0);
		}
		$stmt->closeCursor();
		return $affected;
	}

	/**
	 * Assign values from array with the field id as index and the value as value
	 *
	 * @param array $array
	 */
	public function assignByArray($array) {
		$result=array();
		foreach ($array as $fieldId=>$value) {
			$result[self::$FIELD_NAMES[$fieldId]]=$value;
		}
		$this->assignByHash($result);
	}

	/**
	 * Assign values from hash where the indexes match the tables field names
	 *
	 * @param array $result
	 */
	public function assignByHash($result) {
		$this->setIdUsuario($result['id_usuario']);
		$this->setIdentificacion($result['identificacion']);
		$this->setTipoIdentificacion($result['tipo_identificacion']);
		$this->setApellido($result['apellido']);
		$this->setNombre($result['nombre']);
		$this->setDireccion($result['direccion']);
		$this->setTelefono($result['telefono']);
		$this->setCelular($result['celular']);
		$this->setMail($result['mail']);
		$this->setFechaNacimiento($result['fecha_nacimiento']);
		$this->setEstudianteUniatlantico($result['estudiante_uniatlantico']);
		$this->setFechaRegistro($result['fecha_registro']);
		$this->setActivo($result['activo']);
		$this->setAntiguo($result['antiguo']);
	}

	/**
	 * Get element instance by it's primary key(s).
	 * Will return null if no row was matched.
	 *
	 * @param PDO $db
	 * @return ClUsuarioModel
	 */
	public static function findById(PDO $db,$idUsuario) {
		$stmt=self::prepareStatement($db,self::SQL_SELECT_PK);
		$stmt->bindValue(1,$idUsuario);
		$affected=$stmt->execute();
		if (false===$affected) {
			$stmt->closeCursor();
			throw new Exception($stmt->errorCode() . ':' . var_export($stmt->errorInfo(), true), 0);
		}
		$result=$stmt->fetch(PDO::FETCH_ASSOC);
		$stmt->closeCursor();
		if(!$result) {
			return null;
		}
		$o=new ClUsuarioModel();
		$o->assignByHash($result);
		$o->notifyPristine();
		return $o;
	}

	/**
	 * Bind all values to statement
	 *
	 * @param PDOStatement $stmt
	 */
	protected function bindValues(PDOStatement &$stmt) {
		$stmt->bindValue(1,$this->getIdUsuario());
		$stmt->bindValue(2,$this->getIdentificacion());
		$stmt->bindValue(3,$this->getTipoIdentificacion());
		$stmt->bindValue(4,$this->getApellido());
		$stmt->bindValue(5,$this->getNombre());
		$stmt->bindValue(6,$this->getDireccion());
		$stmt->bindValue(7,$this->getTelefono());
		$stmt->bindValue(8,$this->getCelular());
		$stmt->bindValue(9,$this->getMail());
		$stmt->bindValue(10,$this->getFechaNacimiento());
		$stmt->bindValue(11,$this->getEstudianteUniatlantico());
		$stmt->bindValue(12,$this->getFechaRegistro());
		$stmt->bindValue(13,$this->getActivo());
		$stmt->bindValue(14,$this->getAntiguo());
	}


	/**
	 * Insert this instance into the database
	 *
	 * @param PDO $db
	 * @return mixed
	 */
	public function insertIntoDatabase(PDO $db) {
		if (null===$this->getIdUsuario()) {
			$stmt=self::prepareStatement($db,self::SQL_INSERT_AUTOINCREMENT);
			$stmt->bindValue(1,$this->getIdentificacion());
			$stmt->bindValue(2,$this->getTipoIdentificacion());
			$stmt->bindValue(3,$this->getApellido());
			$stmt->bindValue(4,$this->getNombre());
			$stmt->bindValue(5,$this->getDireccion());
			$stmt->bindValue(6,$this->getTelefono());
			$stmt->bindValue(7,$this->getCelular());
			$stmt->bindValue(8,$this->getMail());
			$stmt->bindValue(9,$this->getFechaNacimiento());
			$stmt->bindValue(10,$this->getEstudianteUniatlantico());
			$stmt->bindValue(11,$this->getFechaRegistro());
			$stmt->bindValue(12,$this->getActivo());
			$stmt->bindValue(13,$this->getAntiguo());
		} else {
			$stmt=self::prepareStatement($db,self::SQL_INSERT);
			$this->bindValues($stmt);
		}
		$affected=$stmt->execute();
		if (false===$affected) {
			$stmt->closeCursor();
			throw new Exception($stmt->errorCode() . ':' . var_export($stmt->errorInfo(), true), 0);
		}
		$lastInsertId=$db->lastInsertId();
		if (false!==$lastInsertId) {
			$this->setIdUsuario($lastInsertId);
		}
		$stmt->closeCursor();
		$this->notifyPristine();
		return $affected;
	}


	/**
	 * Update this instance into the database
	 *
	 * @param PDO $db
	 * @return mixed
	 */
	public function updateToDatabase(PDO $db) {
		$stmt=self::prepareStatement($db,self::SQL_UPDATE);
		$this->bindValues($stmt);
		$stmt->bindValue(15,$this->getIdUsuario());
		$affected=$stmt->execute();
		if (false===$affected) {
			$stmt->closeCursor();
			throw new Exception($stmt->errorCode() . ':' . var_export($stmt->errorInfo(), true), 0);
		}
		$stmt->closeCursor();
		$this->notifyPristine();
		return $affected;
	}


	/**
	 * Delete this instance from the database
	 *
	 * @param PDO $db
	 * @return mixed
	 */
	public function deleteFromDatabase(PDO $db) {
		$stmt=self::prepareStatement($db,self::SQL_DELETE_PK);
		$stmt->bindValue(1,$this->getIdUsuario());
		$affected=$stmt->execute();
		if (false===$affected) {
			$stmt->closeCursor();
			throw new Exception($stmt->errorCode() . ':' . var_export($stmt->errorInfo(), true), 0);
		}
		$stmt->closeCursor();
		return $affected;
	}

	/**
	 * Fetch ClHistoricoAcademicoModel's which this ClUsuarioModel references.
	 * `cl_usuario`.`id_usuario` -> `cl_historico_academico`.`id_usuario`
	 *
	 * @param PDO $db a PDO Database instance
	 * @param array $sort array of DSC instances
	 * @return ClHistoricoAcademicoModel[]
	 */
	public function fetchClHistoricoAcademicoModelCollection(PDO $db, $sort=null) {
		$filter=array(ClHistoricoAcademicoModel::FIELD_ID_USUARIO=>$this->getIdUsuario());
		return ClHistoricoAcademicoModel::findByFilter($db, $filter, true, $sort);
	}

	/**
	 * Fetch ClInscripcionModel's which this ClUsuarioModel references.
	 * `cl_usuario`.`id_usuario` -> `cl_inscripcion`.`id_usuario`
	 *
	 * @param PDO $db a PDO Database instance
	 * @param array $sort array of DSC instances
	 * @return ClInscripcionModel[]
	 */
	public function fetchClInscripcionModelCollection(PDO $db, $sort=null) {
		$filter=array(ClInscripcionModel::FIELD_ID_USUARIO=>$this->getIdUsuario());
		return ClInscripcionModel::findByFilter($db, $filter, true, $sort);
	}

	/**
	 * Fetch ClMatriculaModel's which this ClUsuarioModel references.
	 * `cl_usuario`.`id_usuario` -> `cl_matricula`.`id_usuario`
	 *
	 * @param PDO $db a PDO Database instance
	 * @param array $sort array of DSC instances
	 * @return ClMatriculaModel[]
	 */
	public function fetchClMatriculaModelCollection(PDO $db, $sort=null) {
		$filter=array(ClMatriculaModel::FIELD_ID_USUARIO=>$this->getIdUsuario());
		return ClMatriculaModel::findByFilter($db, $filter, true, $sort);
	}

	/**
	 * Fetch ClUsuarioFamiliaModel's which this ClUsuarioModel references.
	 * `cl_usuario`.`id_usuario` -> `cl_usuario_familia`.`id_usuario`
	 *
	 * @param PDO $db a PDO Database instance
	 * @param array $sort array of DSC instances
	 * @return ClUsuarioFamiliaModel[]
	 */
	public function fetchClUsuarioFamiliaModelCollection(PDO $db, $sort=null) {
		$filter=array(ClUsuarioFamiliaModel::FIELD_ID_USUARIO=>$this->getIdUsuario());
		return ClUsuarioFamiliaModel::findByFilter($db, $filter, true, $sort);
	}

	/**
	 * return array with the property name as index and the field value as value.
	 * ezComponents support method
	 *
	 * @return array
	 */
	public function getState() {
		$array=$this->toArray();
		$state=array();
		foreach ($array as $fieldId=>$value) {
			$state[self::$PROPERTY_NAMES[$fieldId]]=$value;
		}
		return $state;
	}

	/**
	 * Assign values from hash where the indexes match the property names.
	 * ezComponents support method
	 *
	 * @param array $state
	 */
	public function setState(array $state) {
		$propertyNameToFieldId=array_flip(self::$PROPERTY_NAMES);
		$hash=$this->toHash();
		foreach ($state as $propertyName=>$value) {
			$hash[self::$FIELD_NAMES[$propertyNameToFieldId[$propertyName]]]=$value;
		}
		$this->assignByHash($hash);
	}

	/**
	 * get persistence definition for ezComponents
	 *
	 * @return ezcPersistentObjectDefinition
	 */
	public static function toEzcPersistentObjectDefinition() {
		static $typeMapping=array(
			Db2PhpEntity::PHP_TYPE_BOOL=>ezcPersistentObjectProperty::PHP_TYPE_BOOL,
			Db2PhpEntity::PHP_TYPE_INT=>ezcPersistentObjectProperty::PHP_TYPE_INT,
			Db2PhpEntity::PHP_TYPE_FLOAT=>ezcPersistentObjectProperty::PHP_TYPE_FLOAT,
			Db2PhpEntity::PHP_TYPE_STRING=>ezcPersistentObjectProperty::PHP_TYPE_STRING
		);
		$def=new ezcPersistentObjectDefinition();
		$def->table=self::SQL_TABLE_NAME;
		$def->class='ClUsuarioModel';
		if (!empty (self::$PRIMARY_KEYS)) {
			$pkField=self::$PRIMARY_KEYS[0];
			$def->idProperty=new ezcPersistentObjectIdProperty();
			$def->idProperty->columnName=self::$FIELD_NAMES[$pkField];
			$def->idProperty->propertyName=self::$PROPERTY_NAMES[$pkField];
			$def->idProperty->generator=new ezcPersistentGeneratorDefinition(
				in_array($pkField, self::$AUTOINCREMENT_FIELDS) ? 'ezcPersistentNativeGenerator' : 'ezcPersistentManualGenerator');
		} else {
			$pkField=null;
		}
		foreach (self::$PROPERTY_NAMES as $fieldId=>$propertyName) {
			if ($fieldId!==$pkField) {
				$def->properties[$propertyName]=new ezcPersistentObjectProperty();
				$def->properties[$propertyName]->columnName=self::$FIELD_NAMES[$fieldId];
				$def->properties[$propertyName]->propertyName=$propertyName;
				$def->properties[$propertyName]->propertyType=$typeMapping[self::$PROPERTY_TYPES[$fieldId]];
			}
		}
		return $def;
	}


	/**
	 * get element as DOM Document
	 *
	 * @return DOMDocument
	 */
	public function toDOM() {
		return self::hashToDomDocument($this->toHash(), 'ClUsuarioModel');
	}

	/**
	 * get single ClUsuarioModel instance from a DOMElement
	 *
	 * @param DOMElement $node
	 * @return ClUsuarioModel
	 */
	public static function fromDOMElement(DOMElement $node) {
		$o=new ClUsuarioModel();
		$o->assignByHash(self::domNodeToHash($node, self::$FIELD_NAMES, self::$DEFAULT_VALUES, self::$FIELD_TYPES));
			$o->notifyPristine();
		return $o;
	}

	/**
	 * get all instances of ClUsuarioModel from the passed DOMDocument
	 *
	 * @param DOMDocument $doc
	 * @return ClUsuarioModel[]
	 */
	public static function fromDOMDocument(DOMDocument $doc) {
		$instances=array();
		foreach ($doc->getElementsByTagName('ClUsuarioModel') as $node) {
			$instances[]=self::fromDOMElement($node);
		}
		return $instances;
	}

}
?>